//
//  WLHomeHealthDataCell.swift
//  WalkerLove
//
//  Created by Z on 2020/4/18.
//  Copyright © 2020 Carlson. All rights reserved.
//  健康数据

import UIKit

class WLHomeHealthDataCell: UITableViewCell {

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initSubviews()
    }
    
    func initSubviews() {
        self.backgroundColor = UIColor.clear
        let bgView = UIView()
        bgView.backgroundColor = UIColor.white
        contentView.addSubview(bgView)
        bgView.layer.cornerRadius = 9
        bgView.layer.shadowColor = UIColor.gray.cgColor
        bgView.layer.shadowOffset = CGSize(width: 0, height: 5.5)
        bgView.layer.shadowOpacity = 0.1
        bgView.layer.shadowRadius = 11
        bgView.snp.makeConstraints({
            $0.left.equalToSuperview().offset(15)
            $0.right.equalToSuperview().offset(-15)
            $0.top.equalToSuperview().offset(10)
            $0.height.equalTo(74)
        })
        
        let imgs = ["home_health_data_1", "home_health_data_2", "home_health_data_3"]
        let titles = ["步行里程", "步行时间", "卡路里"]
        let f_w = (kScreen.width-70)/3;
        for i in 0..<3 {
            let view = creatView(hImgName: imgs[i], hStr: titles[i])
            bgView.addSubview(view)
            
            view.snp.makeConstraints({
                $0.top.equalToSuperview().offset(15)
                $0.left.equalToSuperview().offset(CGFloat(i)*f_w + 20)
                $0.size.equalTo(CGSize(width: f_w, height: 13))
            })
        }
    }
    
    func creatView(hImgName: String, hStr: String) -> UIView {
        let view = UIView()
        let image = UIImage(named: hImgName)
        let imgView = UIImageView(image: image)
        let lab = UILabel()
        lab.text = hStr
        lab.textColor = DeviceTool.ColorFromRGB(0xA4A4A4)
        lab.font = UIFont(name: "PingFangSC-Regular", size: 12)
        lab.textAlignment = NSTextAlignment.left
        view.addSubview(imgView)
        view.addSubview(lab)
        
        imgView.snp.makeConstraints({
            $0.left.equalToSuperview()
            $0.centerY.equalToSuperview()
            $0.size.equalTo(image!.size)
        })
        lab.snp.makeConstraints({
            $0.left.equalTo(imgView.snp_right).offset(4)
            $0.centerY.equalToSuperview()
        })
        
        return view
    }
}
